import request from '@/utils/zyrequest'
import qs from 'qs'
import { getToken } from '@/utils/auth'


export default {

    // 设备管理
    searchdevice(page, size) {
        return request({
            url: '/item/device/devicedetail',
            method: 'get',
            params: {
                page: `${page}`,
                size: `${size}`
            },
            headers: {
                // 'token': getToken()
            }
        })
    },

    // 设备根据名称查询
    searchBydeviceName(tName, page, size) {
        return request({
            url: '/item/device/devicedetail',
            method: 'get',
            params: {
                tName: `${tName}`,
                page: `${page}`,
                size: `${size}`
            },
            headers: {
                // 'token': getToken()
            }
        })
    },

    // 设备数据查询
    searchDeviceData(page, size, tSerialNumber) {
        return request({
            url: '/item/devicedata/list',
            method: 'get',
            params: {
                page: `${page}`,
                size: `${size}`,
                tSerialNumber: `${tSerialNumber}`
            },
            headers: {
                // 'token': getToken()
            }
        })
    },

    // 最新数据查询
    searchDeviceNewData(){
        return request({
            url: '/item/devicedata/newData',
            method: 'get',
            headers: {
                // 'token': getToken()
            }
        })
    },

    // 最近一天数据查询
    searchNewDayData(name) {
        return request({
            url: '/item/devicedata/eachDeviceData',
            method: 'get',
            params: {
                deviceName: `${name}`
            },
            headers: {
                // 'token': getToken()
            }
        })
    },

    // 新增设备
    insertDevice(query) {
        return request({
            url: '/item/device/devicedetail',
            method: 'post',
            data: JSON.stringify(query),
            headers: {
                'Content-Type': 'application/json;charset=UTF-8',
                // 'token': getToken()  
            }
        })
    },

    // 修改设备
    updateDevice(query) {
        return request({
            url: '/item/device/devicedetail',
            method: 'put',
            data: JSON.stringify(query),
            headers: {
                'Content-Type': 'application/json;charset=UTF-8',
                // 'token': getToken()  
            }
        })
    },

    // 删除设备
    deleteDevice(id) {
        return request({
            url: '/item/device/devicedetail',
            method: 'delete',
            params: {
                id: `${id}`
            },
            headers: {
                // 'token': getToken()
            }
        })
    },

    // 删除采集的环境数据
    deleteDeviceData(id) {
        return request({
            url: '/item/devicedata/warning',
            method: 'delete',
            params: {
                id: `${id}`
            }
        })
    }
}